import os
import subprocess
import winreg


# 列出所有环境变量的路径
paths_to_add = [
    'C:\\ProgramData\\anaconda3',
    'C:\\ProgramData\\anaconda3\\Library\\mingw-w64\\bin',
    'C:\\ProgramData\\anaconda3\\Library\\usr\\bin',
    'C:\\ProgramData\\anaconda3\\Library\\bin',
    'C:\\ProgramData\\anaconda3\\Scripts',
    'C:\\ProgramData\\anaconda3\\bin',
    'C:\\ProgramData\\anaconda3\\condabin',
    'C:\\VulkanSDK\\1.3.216.0\\Bin',
    'C:\\Program Files (x86)\\Common Files\\Intel\\Shared Libraries\\redist\\intel64\\compiler',
    'C:\\Program Files\\PlasticSCM5\\server',
    'C:\\Program Files\\PlasticSCM5\\client',
    'C:\\Windows\\system32',
    'C:\\Windows',
    'C:\\Windows\\System32\\Wbem',
    'C:\\Windows\\System32\\WindowsPowerShell\\v1.0',
    'C:\\Windows\\System32\\OpenSSH',
    'C:\\Program Files\\Microsoft SQL Server\\120\\Tools\\Binn',
    'C:\\Program Files\\Common Files\\Autodesk Shared',
    'C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\130\\Tools\\Binn',
    'C:\\Program Files (x86)\\Microsoft SQL Server\\140\\Tools\\Binn',
    'C:\\Program Files\\Microsoft SQL Server\\140\\Tools\\Binn',
    'C:\\Program Files\\Microsoft SQL Server\\140\\DTS\\Binn',
    'C:\\Program Files (x86)\\Microsoft SQL Server\\Client SDK\\ODBC\\130\\Tools\\Binn',
    'C:\\Program Files (x86)\\Microsoft SQL Server\\140\\DTS\\Binn',
    'C:\\Program Files (x86)\\Microsoft SQL Server\\140\\Tools\\Binn\\ManagementStudio',
    'C:\\Program Files\\nodejs',
    'C:\\Program Files\\dotnet',
    'C:\\Program Files\\Git\\cmd',
    'C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common',
    'C:\\Program Files\\NVIDIA Corporation\\NVIDIA NvDLISR',
    'C:\\Program Files\\PuTTY',
    'C:\\Program Files\\doxygen\\bin',
    'C:\\Program Files (x86)\\Microsoft SQL Server\\160\\DTS\\Binn',
    'C:\\Program Files\\Azure Data Studio\\bin',
    'C:\\Program Files\\MiKTeX\\miktex\\bin\\x64',
    'C:\\Program Files\\CMake\\bin',
    'C:\\ProgramData\\anaconda3\\Scripts',
    'C:\\ProgramData\\anaconda3',
    'C:\\ProgramData\\anaconda3\\Library\\bin',
    'C:\\ffmpeg\\bin',
    'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance Toolkit',
    'C:\\Program Files\\Microsoft SQL Server\\150\\Tools\\Binn',
    'C:\\msys64\\ucrt64\\bin',
    'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python312\\Scripts',
    'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python312',
    'C:\\Users\\Administrator\\AppData\\Local\\Microsoft\\WindowsApps',
    'C:\\Users\\Administrator\\AppData\\Roaming\\npm',
    'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Microsoft VS Code\\bin',
    'C:\\Users\\Administrator\\.dotnet\\tools',
    'C:\\Users\\Administrator\\AppData\\Local\\GitHubDesktop\\bin',
    'C:\\Program Files\\JetBrains\\JetBrains Rider 2023.2.2\\bin',
    'C:\\Program Files\\Azure Data Studio\\bin',
    'C:\\Program Files\\JetBrains\\PyCharm Community Edition 2024.1\\bin',
    'C:\\dev\\games101t\\Rasterizer\\vendor\\opencv\\opencv\\build\\x64\\vc16\\bin',

]

def add_to_path(new_paths):
    # 获取当前 PATH 变量的值
    key_path = r'SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
    reg_key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, key_path, 0, winreg.KEY_ALL_ACCESS)
    current_path, _ = winreg.QueryValueEx(reg_key, 'Path')

    # 将新的路径添加到当前 PATH 变量中
    new_path_list = new_paths
    new_path_set = set(new_path_list)
    new_path_sorted = sorted(new_path_set)
    new_path = ';'.join(new_path_sorted)

    # 设置新的 PATH 变量值到注册表
    winreg.SetValueEx(reg_key, 'Path', 0, winreg.REG_EXPAND_SZ, new_path)

    # 关闭注册表键
    winreg.CloseKey(reg_key)
    print('已成功更新系统的 PATH 环境变量。')

# 调用函数来重置环境变量
add_to_path(paths_to_add)


